# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=chromium
pkgver=103.0.5060.114
pkgrel=0
pkgdesc="Chromium web browser"
url="https://www.chromium.org/Home"
arch="aarch64 x86_64"	# x86: ./v8_context_snapshot_generator segfaults
license="BSD-3-Clause"
makedepends="
	alsa-lib-dev
	bash
	bison flex
	bsd-compat-headers
	bzip2-dev
	cairo-dev
	clang-dev
	cups-dev
	curl-dev
	dbus-glib-dev
	elfutils
	elfutils-dev
	eudev-dev
	ffmpeg-dev
	findutils
	flac-dev
	freetype-dev
	gperf
	gtk+3.0-dev
	gzip
	harfbuzz-dev
	hunspell-dev
	hwids-usb
	java-jdk
	jpeg-dev
	jsoncpp-dev
	krb5-dev
	lcms2-dev
	libbsd-dev
	libcap-dev
	libevent-dev
	libexif-dev
	libgcrypt-dev
	libgnome-keyring-dev
	libjpeg-turbo-dev
	libpng-dev
	libusb-dev
	libva-dev
	libwebp-dev
	libxcomposite-dev
	libxcursor-dev
	libxinerama-dev
	libxml2-dev
	libxrandr-dev
	libxscrnsaver-dev
	libxslt-dev
	linux-headers
	lld
	mesa-dev
	minizip-dev
	ninja
	nodejs
	nss-dev
	opus-dev
	pciutils-dev
	perl
	pipewire-dev
	pulseaudio-dev
	py3-setuptools
	python3
	re2-dev
	snappy-dev
	speex-dev
	sqlite-dev
	xcb-proto
	xdg-utils
	zlib-dev
	"
# explicit depends for --headless
# XXX: eudev-libs replaced by so:libudev.so.1 to allow installation with libudev-zero
# take care if libudev.so ever updates somajor..
depends="xdg-utils so:libudev.so.1 gtk+3.0 font-opensans"
options="suid !check" # broken
subpackages="
	$pkgname-angle
	$pkgname-chromedriver
	$pkgname-doc
	$pkgname-lang
	$pkgname-swiftshader
	"
source="https://commondatastorage.googleapis.com/chromium-browser-official/chromium-$pkgver.tar.xz
	test_fonts-cd96fc55dc243f6c6f4cb63ad117cad6cd48dceb.tar.gz::https://chromium-fonts.storage.googleapis.com/cd96fc55dc243f6c6f4cb63ad117cad6cd48dceb
	chromium-launcher.sh
	chromium.conf
	google-api.keys

	default-pthread-stacksize.patch
	musl-fixes.patch
	no-getcontext.patch
	musl-hacks.patch
	musl-libc++.patch
	musl-sandbox.patch
	no-execinfo.patch
	no-mallinfo.patch
	resolver.patch
	musl-stat.patch

	chromium-use-alpine-target.patch
	media-base.patch
	musl-crashpad.patch
	musl-v8-monotonic-pthread-cont_timedwait.patch
	nasm.patch

	elf-arm.patch

	fix-narrowing-cast.patch

	fix-unittests-sandbox.patch

	chromium-revert-drop-of-system-java.patch
	scoped-file.patch
	remove-strip_binary.patch
	gdbinit.patch
	quiche-arena-size.patch

	revert-use-ffile-compilation-dir.patch
	chromium-VirtualCursor-standard-layout.patch

	credentials-header.patch

	musl-tid-caching.patch

	memory-tagging-arm64.patch
	fix-missing-cstdint-include-musl.patch

	roll-src-third_party-ffmpeg.patch
	remove-no-opaque-pointers-flag.patch
"

# secfixes:
#   103.0.5060.114-r0:
#     - CVE-2022-2294
#     - CVE-2022-2295
#     - CVE-2022-2296
#   103.0.5060.53-r0:
#     - CVE-2022-2156
#     - CVE-2022-2157
#     - CVE-2022-2158
#     - CVE-2022-2160
#     - CVE-2022-2161
#     - CVE-2022-2162
#     - CVE-2022-2163
#     - CVE-2022-2164
#     - CVE-2022-2165
#   102.0.5005.61-r0:
#     - CVE-2022-1853
#     - CVE-2022-1854
#     - CVE-2022-1855
#     - CVE-2022-1856
#     - CVE-2022-1857
#     - CVE-2022-1858
#     - CVE-2022-1859
#     - CVE-2022-1860
#     - CVE-2022-1861
#     - CVE-2022-1862
#     - CVE-2022-1863
#     - CVE-2022-1864
#     - CVE-2022-1865
#     - CVE-2022-1866
#     - CVE-2022-1867
#     - CVE-2022-1868
#     - CVE-2022-1869
#     - CVE-2022-1870
#     - CVE-2022-1871
#     - CVE-2022-1872
#     - CVE-2022-1873
#     - CVE-2022-1874
#     - CVE-2022-1875
#     - CVE-2022-1876
#   101.0.4951.64-r0:
#     - CVE-2022-1633
#     - CVE-2022-1634
#     - CVE-2022-1635
#     - CVE-2022-1636
#     - CVE-2022-1637
#     - CVE-2022-1638
#     - CVE-2022-1639
#     - CVE-2022-1640
#     - CVE-2022-1641
#   101.0.4951.54-r0:
#     - CVE-2022-1477
#     - CVE-2022-1478
#     - CVE-2022-1479
#     - CVE-2022-1481
#     - CVE-2022-1482
#     - CVE-2022-1483
#     - CVE-2022-1484
#     - CVE-2022-1485
#     - CVE-2022-1486
#     - CVE-2022-1487
#     - CVE-2022-1488
#     - CVE-2022-1489
#     - CVE-2022-1490
#     - CVE-2022-1491
#     - CVE-2022-1492
#     - CVE-2022-1493
#     - CVE-2022-1494
#     - CVE-2022-1495
#     - CVE-2022-1496
#     - CVE-2022-1497
#     - CVE-2022-1498
#     - CVE-2022-1499
#     - CVE-2022-1500
#     - CVE-2022-1501
#   100.0.4896.127-r0:
#     - CVE-2022-1364
#   99.0.4844.84-r0:
#     - CVE-2022-1096
#   98.0.4758.102-r0:
#     - CVE-2022-0452
#     - CVE-2022-0453
#     - CVE-2022-0454
#     - CVE-2022-0455
#     - CVE-2022-0456
#     - CVE-2022-0457
#     - CVE-2022-0458
#     - CVE-2022-0459
#     - CVE-2022-0460
#     - CVE-2022-0461
#     - CVE-2022-0462
#     - CVE-2022-0463
#     - CVE-2022-0464
#     - CVE-2022-0465
#     - CVE-2022-0466
#     - CVE-2022-0467
#     - CVE-2022-0468
#     - CVE-2022-0469
#     - CVE-2022-0470
#     - CVE-2022-0603
#     - CVE-2022-0604
#     - CVE-2022-0605
#     - CVE-2022-0606
#     - CVE-2022-0607
#     - CVE-2022-0608
#     - CVE-2022-0609
#     - CVE-2022-0610
#   93.0.4577.82-r0:
#     - CVE-2021-30625
#     - CVE-2021-30626
#     - CVE-2021-30627
#     - CVE-2021-30628
#     - CVE-2021-30629
#     - CVE-2021-30630
#     - CVE-2021-30631
#     - CVE-2021-30632
#     - CVE-2021-30633
#   93.0.4577.63-r0:
#     - CVE-2021-30606
#     - CVE-2021-30607
#     - CVE-2021-30608
#     - CVE-2021-30609
#     - CVE-2021-30610
#     - CVE-2021-30611
#     - CVE-2021-30612
#     - CVE-2021-30613
#     - CVE-2021-30614
#     - CVE-2021-30615
#     - CVE-2021-30616
#     - CVE-2021-30617
#     - CVE-2021-30618
#     - CVE-2021-30619
#     - CVE-2021-30620
#     - CVE-2021-30621
#     - CVE-2021-30622
#     - CVE-2021-30623
#     - CVE-2021-30624
#   92.0.4515.159-r0:
#     - CVE-2021-30598
#     - CVE-2021-30599
#     - CVE-2021-30600
#     - CVE-2021-30601
#     - CVE-2021-30602
#     - CVE-2021-30603
#     - CVE-2021-30604
#     - CVE-2021-30590
#     - CVE-2021-30591
#     - CVE-2021-30592
#     - CVE-2021-30593
#     - CVE-2021-30594
#     - CVE-2021-30596
#     - CVE-2021-30597
#   92.0.4515.107-r0:
#     - CVE-2021-30565
#     - CVE-2021-30566
#     - CVE-2021-30567
#     - CVE-2021-30568
#     - CVE-2021-30569
#     - CVE-2021-30571
#     - CVE-2021-30572
#     - CVE-2021-30573
#     - CVE-2021-30574
#     - CVE-2021-30575
#     - CVE-2021-30576
#     - CVE-2021-30577
#     - CVE-2021-30578
#     - CVE-2021-30579
#     - CVE-2021-30580
#     - CVE-2021-30581
#     - CVE-2021-30582
#     - CVE-2021-30583
#     - CVE-2021-30584
#     - CVE-2021-30585
#     - CVE-2021-30586
#     - CVE-2021-30587
#     - CVE-2021-30588
#     - CVE-2021-30589
#   91.0.4472.164-r0:
#     - CVE-2021-30559
#     - CVE-2021-30541
#     - CVE-2021-30560
#     - CVE-2021-30561
#     - CVE-2021-30562
#     - CVE-2021-30563
#     - CVE-2021-30564
#   91.0.4472.114-r0:
#     - CVE-2021-30554
#     - CVE-2021-30555
#     - CVE-2021-30556
#     - CVE-2021-30557
#   91.0.4472.101-r0:
#     - CVE-2021-30544
#     - CVE-2021-30545
#     - CVE-2021-30546
#     - CVE-2021-30547
#     - CVE-2021-30548
#     - CVE-2021-30549
#     - CVE-2021-30550
#     - CVE-2021-30551
#     - CVE-2021-30552
#     - CVE-2021-30553
#   91.0.4472.77-r0:
#     - CVE-2021-30521
#     - CVE-2021-30522
#     - CVE-2021-30523
#     - CVE-2021-30524
#     - CVE-2021-30525
#     - CVE-2021-30526
#     - CVE-2021-30527
#     - CVE-2021-30528
#     - CVE-2021-30529
#     - CVE-2021-30530
#     - CVE-2021-30531
#     - CVE-2021-30532
#     - CVE-2021-30533
#     - CVE-2021-30534
#     - CVE-2021-30535
#     - CVE-2021-30536
#     - CVE-2021-30537
#     - CVE-2021-30538
#     - CVE-2021-30539
#     - CVE-2021-30540
#   90.0.4430.72-r0:
#     - CVE-2021-21201
#     - CVE-2021-21202
#     - CVE-2021-21203
#     - CVE-2021-21204
#     - CVE-2021-21205
#     - CVE-2021-21221
#     - CVE-2021-21207
#     - CVE-2021-21208
#     - CVE-2021-21209
#     - CVE-2021-21210
#     - CVE-2021-21211
#     - CVE-2021-21212
#     - CVE-2021-21213
#     - CVE-2021-21214
#     - CVE-2021-21215
#     - CVE-2021-21216
#     - CVE-2021-21217
#     - CVE-2021-21218
#     - CVE-2021-21219
#   89.0.4389.128-r0:
#     - CVE-2021-21206
#     - CVE-2021-21220
#   89.0.4389.114-r0:
#     - CVE-2021-21194
#     - CVE-2021-21195
#     - CVE-2021-21196
#     - CVE-2021-21197
#     - CVE-2021-21198
#     - CVE-2021-21199
#   89.0.4389.90-r0:
#     - CVE-2021-21191
#     - CVE-2021-21192
#     - CVE-2021-21193
#   89.0.4389.72-r0:
#     - CVE-2021-21158
#     - CVE-2021-21159
#     - CVE-2021-21160
#     - CVE-2021-21161
#     - CVE-2021-21162
#     - CVE-2021-21163
#     - CVE-2021-21164
#     - CVE-2021-21165
#     - CVE-2021-21166
#     - CVE-2021-21167
#     - CVE-2021-21168
#     - CVE-2021-21169
#     - CVE-2021-21170
#     - CVE-2021-21171
#     - CVE-2021-21172
#     - CVE-2021-21173
#     - CVE-2021-21174
#     - CVE-2021-21175
#     - CVE-2021-21176
#     - CVE-2021-21177
#     - CVE-2021-21178
#     - CVE-2021-21179
#     - CVE-2021-21180
#     - CVE-2020-27844
#     - CVE-2021-21181
#     - CVE-2021-21182
#     - CVE-2021-21183
#     - CVE-2021-21184
#     - CVE-2021-21185
#     - CVE-2021-21186
#     - CVE-2021-21187
#     - CVE-2021-21188
#     - CVE-2021-21189
#     - CVE-2021-21190
#   83.0.4103.116-r0:
#     - CVE-2020-6505
#     - CVE-2020-6506
#     - CVE-2020-6507
#     - CVE-2020-6509
#   72.0.3626.121-r0:
#     - CVE-2019-5786

if [ -n "$CHECK" ]; then
	options="suid"
fi

_buildtype=Release
if [ -n "$DEBUG" ]; then
	_symbol_level=2
	subpackages="$subpackages $pkgname-dbg"
else
	_symbol_level=0
fi

upstream_version() {
	curl --silent https://omahaproxy.appspot.com/all \
		| awk -F, '$1 == "linux" && $2 == "stable" {print $3}'
}

prepare() {
	default_prepare

	cd "$srcdir"/"chromium-$pkgver"

	mv ../test_fonts/ ./third_party/test_fonts/

	# https://groups.google.com/a/chromium.org/d/topic/chromium-packagers/9JX1N2nf4PU/discussion
	touch chrome/test/data/webui/i18n_process_css_test.html
	# Use the file at run time instead of effectively compiling it in
	sed 's|//third_party/usb_ids/usb.ids|/usr/share/hwdata/usb.ids|g' \
		-i services/device/public/cpp/usb/BUILD.gn

	mkdir -p third_party/node/linux/node-linux-x64/bin
	ln -s /usr/bin/node third_party/node/linux/node-linux-x64/bin/

	# reusable system library settings
	local use_system="
		ffmpeg
		flac
		fontconfig
		freetype
		harfbuzz-ng
		libdrm
		libevent
		libjpeg
		libpng
		libwebp
		libxml
		libxslt
		opus
		re2
		snappy
		"
	for _lib in $use_system libjpeg_turbo; do
		msg "Removing buildscripts for system provided $_lib"
		find . -type f -path "*third_party/$_lib/*" \
			\! -path "*third_party/$_lib/chromium/*" \
			\! -path "*third_party/$_lib/google/*" \
			\! -path './base/third_party/icu/*' \
			\! -path './third_party/libxml/*' \
			\! -path './third_party/pdfium/third_party/freetype/include/pstables.h' \
			\! -path './third_party/harfbuzz-ng/utils/hb_scoped.h' \
			\! -regex '.*\.\(gn\|gni\|isolate\|py\)' \
			-delete
	done

	msg "Replacing gn files"
	python3 build/linux/unbundle/replace_gn_files.py --system-libraries \
		$use_system
	python3 third_party/libaddressinput/chromium/tools/update-strings.py

	# prevent annoying errors when regenerating gni
	sed -i 's,^update_readme$,#update_readme,' \
		third_party/libvpx/generate_gni.sh

	# allow system dependencies in "official builds"
	sed -i 's/OFFICIAL_BUILD/GOOGLE_CHROME_BUILD/' \
		tools/generate_shim_headers/generate_shim_headers.py
}

_gn_flags() {
	echo "$@"
}

build() {
	##############################################################
	# Please dont use these keys outside of Alpine Linux project #
	# You can create your own at:                                #
	# http://www.chromium.org/developers/how-tos/api-keys        #
	##############################################################
	local _google_api_key _google_default_client_id _google_default_client_secret
	eval "$(base64 -d < $srcdir/google-api.keys)"

	# silence really annoying warning on every compiler invocation
	export CFLAGS="$CFLAGS -O2 -Wno-unknown-warning-option"
	export CXXFLAGS="$CXXFLAGS -O2 -Wno-unknown-warning-option"

	msg "Bootstrapping GN"

#	AR="ar" CC="${CC:-gcc}" CXX="${CXX:-g++}" LD="${CXX:-g++}" \
	# shellcheck disable=SC2097,SC2098
	CC="${CC:-clang}" CXX="${CXX:-clang++}" LD="${CXX:-clang++}" \
		python3 tools/gn/bootstrap/bootstrap.py -s -v --skip-generate-buildfiles

	msg "Configuring build"

	local _c _ca
	_c=$(_gn_flags \
		blink_symbol_level=$_symbol_level \
		build_with_tflite_lib=false \
		chrome_pgo_phase=0 \
		clang_use_chrome_plugins=false \
		custom_toolchain=\"//build/toolchain/linux/unbundle:default\" \
		disable_fieldtrial_testing_config=true \
		enable_hangout_services_extension=true \
		enable_nacl=false \
		enable_precompiled_headers=false \
		enable_vr=false \
		fatal_linker_warnings=false \
		ffmpeg_branding=\"Chrome\" \
		gold_path=\"/usr/bin/ld.gold\" \
		google_api_key=\"$_google_api_key\" \
		google_default_client_id=\"$_google_default_client_id\" \
		google_default_client_secret=\"$_google_default_client_secret\" \
		host_toolchain=\"//build/toolchain/linux/unbundle:default\" \
		icu_use_data_file=true \
		is_cfi=false \
		is_clang=true \
		is_component_build=false \
		is_debug=false \
		is_official_build=true \
		link_pulseaudio=true \
		proprietary_codecs=true \
		rtc_use_pipewire=true \
		symbol_level=$_symbol_level \
		treat_warnings_as_errors=false \
		use_allocator=\"none\" \
		use_allocator_shim=false \
		use_cfi_icall=false \
		use_cups=true \
		use_custom_libcxx=false \
		use_gnome_keyring=false \
		use_gold=false \
		use_lld=true \
		use_pulseaudio=true \
		use_sysroot=false \
		use_system_freetype=true \
		use_system_harfbuzz=true \
		use_system_lcms2=true \
		use_system_libdrm=true \
		use_system_libjpeg=true \
		use_system_libpng=true \
		use_system_zlib=true \
		use_thin_lto=false \
	)

	case $CARCH in
		x86*|aarch64) _ca="use_vaapi=true" ;;
		*) _ca="concurrent_links=1" ;;
	esac

	AR="ar" CC="clang" CXX="clang++" LD="clang++" NM=/usr/bin/nm \
		out/Release/gn gen out/$_buildtype --args="$_c $_ca"

	msg "Ninja turtles GO!"

	# final link needs lots of file descriptors
	ulimit -n 4096

	ninja -C out/$_buildtype chrome chrome_sandbox chromedriver chrome_crashpad_handler

	if [ -n "$CHECK" ]; then
		ninja -C out/$_buildtype \
			base_unittests \
			base_util_unittests \
			sandbox_linux_unittests \
			chromedriver_unittests \
			crypto_unittests \
			skia_unittests \
			blink_common_unittests \
			ozone_unittests \
			ozone_x11_unittests \
			ozone_gl_unittests \
			absl_hardening_tests \
			# angle_unittests \
			blink_heap_unittests \
			# blink_platform_unittests \
			boringssl_crypto_tests \
			boringssl_ssl_tests \
			cast_unittests \
			capture_unittests \
			# components_browsertests \
			# components_unittests \
			# content_browsertests \
			# content_unittests \
			# crashpad_tests \
			events_unittests \
			gcm_unit_tests \
			gin_unittests \
			google_apis_unittests \
			gpu_unittests \
			gwp_asan_unittests \
			ipc_tests \
			jingle_unittests \
			latency_unittests \
			libjingle_xmpp_unittests \
			liburlpattern_unittests \
			media_blink_unittests \
			media_unittests \
			midi_unittests \
			mojo_unittests \
			net_unittests \
			# cc_unittests \
			# blink_unittests \
			perfetto_unittests \
			# services_unittests \
			shell_dialogs_unittests \
			sql_unittests \
			storage_unittests \
			ui_base_unittests \
			ui_touch_selection_unittests \
			url_unittests \
			# webkit_unit_tests \
			wtf_unittests \
			zlib_unittests
	fi
}

check() {
	out/$_buildtype/base_unittests
	out/$_buildtype/base_util_unittests
	out/$_buildtype/sandbox_linux_unittests # broken + does not compile
	out/$_buildtype/chromedriver_unittests
	out/$_buildtype/crypto_unittests
	out/$_buildtype/skia_unittests
	out/$_buildtype/ozone_unittests
	out/$_buildtype/ozone_x11_unittests # ?
	out/$_buildtype/ozone_gl_unittests # broken
	out/$_buildtype/absl_hardening_tests
	# out/$_buildtype/angle_unittests # broken / does not compile
	out/$_buildtype/blink_common_unittests
	out/$_buildtype/blink_heap_unittests
	# out/$_buildtype/blink_platform_unittests # broken / does not compile
	out/$_buildtype/boringssl_crypto_tests
	out/$_buildtype/boringssl_ssl_tests
	out/$_buildtype/cast_unittests
	out/$_buildtype/capture_unittests --gtest_filter=-*UsingRealWebcam* # broken
	# out/$_buildtype/components_browsertests # broken / does not compile
	# out/$_buildtype/components_unittests # broken / does not compile
	# out/$_buildtype/content_browsertests # broken / does not compile
	# out/$_buildtype/content_unittests # broken / does not compile
	# out/$_buildtype/crashpad_tests # broken / does not compile
	out/$_buildtype/events_unittests
	out/$_buildtype/gcm_unit_tests
	out/$_buildtype/gin_unittests # ?
	out/$_buildtype/google_apis_unittests
	out/$_buildtype/gpu_unittests
	out/$_buildtype/gwp_asan_unittests # broken / required?
	out/$_buildtype/ipc_tests
	out/$_buildtype/jingle_unittests
	out/$_buildtype/latency_unittests
	out/$_buildtype/libjingle_xmpp_unittests
	out/$_buildtype/liburlpattern_unittests
	out/$_buildtype/media_blink_unittests # broken
	out/$_buildtype/media_unittests # broken
	out/$_buildtype/midi_unittests
	out/$_buildtype/mojo_unittests
	out/$_buildtype/net_unittests # broken
	# out/$_buildtype/cc_unittests # broken / does not compile
	# out/$_buildtype/blink_unittests # broken / does not compile
	out/$_buildtype/perfetto_unittests # ?
	# out/$_buildtype/services_unittests # broken / does not compile
	out/$_buildtype/shell_dialogs_unittests
	out/$_buildtype/sql_unittests
	out/$_buildtype/storage_unittests
	out/$_buildtype/ui_base_unittests # ok
	out/$_buildtype/ui_touch_selection_unittests
	out/$_buildtype/url_unittests
	# out/$_buildtype/webkit_unit_tests # broken / does not compile
	out/$_buildtype/wtf_unittests
	out/$_buildtype/zlib_unittests
}

package() {
	cd "$builddir"/out/$_buildtype

	# binaries
	install -Dm755 chrome "$pkgdir"/usr/lib/$pkgname/chrome
	install -Dm4755 chrome_sandbox "$pkgdir"/usr/lib/$pkgname/chrome-sandbox
	install -Dm755 chrome_crashpad_handler "$pkgdir"/usr/lib/$pkgname/chrome_crashpad_handler

	# resources
	install -Dm644 snapshot_blob.bin "$pkgdir"/usr/lib/$pkgname/
	install -Dm644 v8_context_snapshot.bin "$pkgdir"/usr/lib/$pkgname/

	install -m644 icudtl.dat "$pkgdir"/usr/lib/$pkgname/icudtl.dat

	install -Dm755 xdg-mime "$pkgdir"/usr/lib/$pkgname/xdg-mime
	install -Dm755 xdg-settings "$pkgdir"/usr/lib/$pkgname/xdg-settings

	# Vulkan
	install -Dm755 libvulkan.so.1 "$pkgdir"/usr/lib/$pkgname/libvulkan.so.1

	# Angle
	install -Dm755 libEGL.so "$pkgdir"/usr/lib/$pkgname/libEGL.so
	install -Dm755 libGLESv2.so "$pkgdir"/usr/lib/$pkgname/libGLESv2.so

	local pak
	for pak in *.pak; do
		install -Dm644 $pak "$pkgdir"/usr/lib/$pkgname/$pak
	done

	install -Dm755 "$srcdir"/chromium-launcher.sh \
		"$pkgdir"/usr/lib/$pkgname/chromium-launcher.sh

	cp -a MEIPreload "$pkgdir"/usr/lib/$pkgname/

	# Default to en-us and provide everything else through the chromium-lang package
	install -Dm644 locales/en-US.pak "$pkgdir"/usr/lib/$pkgname/locales/en-US.pak

	# It is important that we name the target "chromium-browser",
	# xdg-utils expect it; bug https://bugs.gentoo.org/355517
	mkdir -p "$pkgdir"/usr/bin
	ln -sf /usr/lib/$pkgname/chromium-launcher.sh "$pkgdir"/usr/bin/chromium-browser

	install -Dm644 "$srcdir"/chromium.conf \
		"$pkgdir"/etc/chromium/chromium.conf

	cd "$builddir"
	for size in 24 48 64 128 256; do
		install -Dm644 "chrome/app/theme/chromium/product_logo_$size.png" \
			"$pkgdir/usr/share/icons/hicolor/${size}x$size/apps/chromium.png"
	done

	for size in 16 32; do
		install -Dm644 "chrome/app/theme/default_100_percent/chromium/product_logo_$size.png" \
			"$pkgdir/usr/share/icons/hicolor/${size}x$size/apps/chromium.png"
	done

	sed -i \
		-e 's/@@MENUNAME@@/Chromium/g' \
		-e 's/@@PACKAGE@@/chromium/g' \
		-e 's/@@USR_BIN_SYMLINK_NAME@@/chromium-browser/g' \
		chrome/app/resources/manpage.1.in \
		chrome/installer/linux/common/desktop.template

	sed -ni \
		-e 's/chromium-browser\.desktop/chromium.desktop/' \
		-e '/<update_contact>/d' \
		-e '/<p>/N;/<p>\n.*\(We invite\|Chromium supports Vorbis\)/,/<\/p>/d' \
		-e '/^<?xml/,$p' \
		chrome/installer/linux/common/chromium-browser/chromium-browser.appdata.xml

	install -Dm644 chrome/installer/linux/common/desktop.template \
		"$pkgdir"/usr/share/applications/chromium.desktop
	install -Dm644 chrome/app/resources/manpage.1.in \
		"$pkgdir"/usr/share/man/man1/chromium.1
	install -Dm644 chrome/installer/linux/common/chromium-browser/chromium-browser.appdata.xml \
		"$pkgdir"/usr/share/metainfo/chromium.appdata.xml
}

chromedriver() {
	pkgdesc="WebDriver driver for the Chromium Browser"
	depends="$pkgname=$pkgver-r$pkgrel"

	cd "$builddir"/out/$_buildtype

	mkdir -p "$subpkgdir"/usr/lib/$pkgname "$subpkgdir"/usr/bin

	install -Dm755 chromedriver "$subpkgdir"/usr/lib/$pkgname/chromedriver
	ln -sf /usr/lib/$pkgname/chromedriver "$subpkgdir"/usr/bin/
}

lang() {
	pkgdesc="Languages for package $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel lang"

	cd "$builddir"/out/$_buildtype

	for pak in locales/*.pak; do
		install -Dm644 "$pak" "$subpkgdir"/usr/lib/$pkgname/"$pak"
	done;

	rm "$subpkgdir"/usr/lib/$pkgname/locales/en-US.pak
}

swiftshader() {
	pkgdesc="Chromium web browser: CPU-based implementation of the Vulkan graphics API"
	depends="$pkgname-angle=$pkgver-r$pkgrel"

	cd "$builddir"/out/$_buildtype

	install -Dm755 libvk_swiftshader.so \
		"$subpkgdir"/usr/lib/$pkgname/libvk_swiftshader.so
	install -Dm755 vk_swiftshader_icd.json \
		"$subpkgdir"/usr/lib/$pkgname/vk_swiftshader_icd.json
}

angle() {
	pkgdesc="Chromium web browser: ANGLE based hardware acceleration"
	depends=""

	mkdir -p "$subpkgdir"
}

sha512sums="
f0e3312efcfa19d05219763184e8f8b81b847fe357cc47a6569f16bcd3bffec9ed4aa19b27c8e8f227bebb13161a126c3a07ee5480f18b5280539ae419b90dbb  chromium-103.0.5060.114.tar.xz
f554ccc5d8a5c066634357878c89944cc591809ea6f6c6ef5b35e970e9674e0b3be8fddb06c0d333ddc65211fa09ae5e0b4b483ca70048156c29607c5487c017  test_fonts-cd96fc55dc243f6c6f4cb63ad117cad6cd48dceb.tar.gz
b9a810416dd7a8ffc3a5ced85ad9acebda1665bd08a57eec7b189698cc5f74d2c3fd69044e20fcb83297a43214b2772a1312b2c6122ea0eb716abacf39524d60  chromium-launcher.sh
f6d962b9e4c22dd42183df3db5d3202dab33eccecafb1bf63ca678147289581262db1e5e64cbe8f9c212beefb0a6717bb8d311e497f56b55fe95b8bab2db493f  chromium.conf
2d8237a940ea691bd10b08315429677a587f7ef9692a0cca53bfd066eae82998a6c71f402a8669e9de39f94d7f3280745d1628ea6eac5d76ca7116844d4e0dac  google-api.keys
22da17c649ae9845d6a174187f2b666245a10db8a997169fc214c430fbba10143cfb57f8f6ece5acf856cd9ea09f293a1aca90cdf3e64fd9423b78beac53f517  default-pthread-stacksize.patch
9fbfeb1f52e48658f46e55db29de02b554f24ae79f46bbd89bbf05c20f538c9bb3c8624a6e27907d13d6717e5f55a332b13577d8672539662c90c9a10109b94a  musl-fixes.patch
e8675aff9fccd8b58cc839ef1d9e0e022d66aa94f72baa72e7acf92ceb2691f6a7907cc60ec3a87f894efdd639a3dec7fe702c97d446fcdea99452caec57e002  no-getcontext.patch
20b6931937ae792ddf4e1be7f0cbf0f0931b0afce9f6528b7ae5edb1bb2db070438caa8edc94e915e1e5ab1a191789129877d0353fe8976f537df3775dd3ab5d  musl-hacks.patch
a361989c7ff4a285ed36c499e4fe1e97ed8d904a9b92f8d3c01b056b469490b7d215b6edb803ba3b0955633f58f3682d4fb60cc710cba68153a6b23df3ba7ba9  musl-libc++.patch
ef43fa90b05e2407b6daa822193121cdeef6ee9068175572f0928f156f186be9c77539dfa06863adfaa25afd498ec1b5081f9e476543616f9472b9033fd921dc  musl-sandbox.patch
7aa351e79c29de63972f1f16fbab0465b2569bc0a22174780988e0cdfe4fcaff3c664dd277937bb33f2b77f108d20afa8720c427524b09d26074f9cf6807e147  no-execinfo.patch
c741fafab758a675f7007a450df7d9acfe05149f4ce6dd4cf82dc6e97ddcd6b5b4a6b8e09820c2ad3ea62487f30b34d848739908e95ca8a31ca5baeb7cb9d0d7  no-mallinfo.patch
cd7719c30518aeb659e9b7dc126241f897afe1a231e601271b63ba170e811a93b514c4d2a77680cdf0c846f81fa6db766ac619aa200efb32cbdfff6732a63893  resolver.patch
0c0d3ed0a8f2bcecb2bf4eb56130fcd71031bb63744fb56e1b5a6b9dfbe16680607ff592e24602fe045b819509a70556e240b6fe0e876710977d60185f682df4  musl-stat.patch
ded02360a36283973b9abb4150de3d964749a58017fbbd9f09fb6cb29ec97a8ac99ccadd953633bbb7eb9ec77a078f4df9de5f624d1580f33446ceba5fd3a3f6  chromium-use-alpine-target.patch
599f5ef338b5797e04436bdc88921c31365d2dea2613d40053be6e774f654e2889efb0c0bd55c2c5044a6805510fbc337da555971169a75d584fac93e18256ac  media-base.patch
2e5a83826239849d096aead033eb519338b84e6fbbf58abfcd7cfe40d0b3070b66bcc825ec84406484d73d1a333f1b9d23a8ab44987ab5c8b187076c84cd668b  musl-crashpad.patch
556cc2ba28184a75745f13c673605327f5be590be179eb3f941dc0abded854a814e5da1432a28fb8d4dcdcd66ffd4c94ee1a8824d2cd93b632f48e9310dbc3fa  musl-v8-monotonic-pthread-cont_timedwait.patch
7957aae04e8ef3badbc98c982ba1acb1b9ef5e665440116c704512f11554d7b64ba3643b7ff7d00476a6686324033b0cf762deb78ce798619226380953b9dc9c  nasm.patch
9b1441fe42421ef9ead86a5143bf997d989bd53a8969cdfdf4e0c45f847efc8c1d127e15fb05e2ef5dbefbb228cbdc2849404d74997ca56265599e12e5efd6e4  elf-arm.patch
e60f381c557a15598d71e33b7aacc63be4a8e17b16cdd95047df5e5e9577ad925864ffd64597d5dbc9a4516de13b3f17c26099b36692165df8c66b1b4d399ce9  fix-narrowing-cast.patch
54f07ee9d85577e284e04460e79132fa6769251ceb045561cea811dde0369e9e4cdbcf26566235b0d12c649be4d46fea294f7c6a4e2a75109dc3282e6e7d7993  fix-unittests-sandbox.patch
c4654d5b23c6f5d9502507e534fe1951d6749c62251e49b6adfe10d1569431e7f7a5a6fa5ff09ec30984415ced27a5e20985df8c91295de34af3c84557fa5b91  chromium-revert-drop-of-system-java.patch
8d11b2ba811fdd6280784bfafcef073238324941b4c33e7c9a5ccfde8506242d06e5136d697f047bab3838b43a666f1da404af7b4f4ff9a0c6bf6bdb8448e5b2  scoped-file.patch
91dafba2138175b6618ec4c96c7ea39f3a26f6a09b69adabad4f9355dd84d436f3de3274b31465d5f46deeb452fde64e4cfbbda0bb4ed7e9a25d953e1b73e5d2  remove-strip_binary.patch
82f2bd4aa613e792d3af6e7a8632e0920cf48504a7572fb97d5480ea182fa125fe526e7df1ce4311b5d139a3f78da0f0b54605fbd09d7cd43135906a7639e47f  gdbinit.patch
b72905bcb775920939b6ac69e22166745daf1154fec46377988c329e0e073d14ff85ae93386fc0d345cd47d3dcfd6b8be56e39277c40637315151bca28f1b904  quiche-arena-size.patch
2fdd0b2fd403dd4440533288f7e08bb8480702c42c7571ea764aac18ba5eaf72494793c77e4244991d12f45e5acfceae0772995b11d323916c07cb53c43a2f59  revert-use-ffile-compilation-dir.patch
0fc131ef4ad32964815744080f40cc2566c70da1cd4ddaf1da8456d1c86e67e3ebf38f43208d17d40b646744e8e662f5b314e236a1c90bc6f8b936313e42a3cf  chromium-VirtualCursor-standard-layout.patch
274858323d040ac8c51bac90b6ef91bb075d7b8d92d73952ed700c10a8bae2c2115fb2a9cc6912de79be226c141d7106839fc3486e22c0206e75cb6d8ff65ee6  credentials-header.patch
a018cf58b9e34f73d588961f2f9a36de67267060fb2e77ebc562974c6c92a59009161e374cf9bbdc35e8bf1a7e90f0b90117a0d494dcd2e2bb2f5e6534925d0b  musl-tid-caching.patch
63e5b25c49af484964b3ac723da1c2f348812572a2e24ad412d2fb9eb7eec9ddc0e76568e76d1f352cdc562bc5003c93e04ee519a82e8568f48484d1682e237f  memory-tagging-arm64.patch
8bebf4a9d5225c6e47edc5b07c4b97be24a45cc221f49632836915ceeb4ecb69b7f79a31ea7f82171cde3443f45fec541f409892542cf1014e81aa6acd01566d  fix-missing-cstdint-include-musl.patch
128ec0fd14349e065c8bb0910d53cbea7423182a06e06f7b7765f3cba1e5ba5e7a8bccbcdab079335b5235abb7bf0d46dee21ecc8c221be7e1c5c6d9795f958e  roll-src-third_party-ffmpeg.patch
c8e892e36e7292cd6db36017fff994a0fbc00dd83ea9010422c21cd56da89c9eddd1712e4ff4b3fec354fa595ce3cc403b96fc13525e74fe6538461d5c2d9b50  remove-no-opaque-pointers-flag.patch
"
